package com.taptech.doufu.ui.adapter;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.bean.DFHomeBannerBean;
import com.taptech.doufu.util.GlideUtil;

import java.util.List;


/**
 * author zhangyongcun
 * 16/9/27
 */

public class MoreBannerAdapter extends RecyclerView.Adapter<MoreBannerAdapter.ViewHolder> {

    List<DFHomeBannerBean> dfHomeBannerBeanArrayList;


    public MoreBannerAdapter(List dfHomeBannerBeanArrayList) {
        this.dfHomeBannerBeanArrayList = dfHomeBannerBeanArrayList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.more_banner_item,parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        DFHomeBannerBean dfHomeBannerBean = dfHomeBannerBeanArrayList.get(position);
        if (dfHomeBannerBean.getTitle() == null) {
            holder.itemTxt.setText(dfHomeBannerBean.getName());
        }else {
            holder.itemTxt.setText(dfHomeBannerBean.getTitle());
        }
        if (dfHomeBannerBean.getBanner_img() != null) {
            if (dfHomeBannerBean.getBanner_img().indexOf("http") == -1) {
                GlideUtil.displayImage(holder.itemImg,"http://imgold2.doufu.la/" + dfHomeBannerBean.getBanner_img());
//                Picasso.with(WeMediaApplication.getInstance()).load("http://imgold2.doufu.la/" + dfHomeBannerBean.getImage()).into(holder.itemImg);
            }else {
                GlideUtil.displayImage(holder.itemImg,dfHomeBannerBean.getBanner_img());
//                Picasso.with(WeMediaApplication.getInstance()).load(dfHomeBannerBean.getImage()).into(holder.itemImg);
            }
        }else {
            if (dfHomeBannerBean.getImages() != null && dfHomeBannerBean.getImages()[0] != null) {
                GlideUtil.displayImage(holder.itemImg,dfHomeBannerBean.getImages()[0].getImgUrl());

//                Picasso.with(WeMediaApplication.getInstance()).load(dfHomeBannerBean.getImages()[0].getImgurl()).into(holder.itemImg);
            }
        }
    }

    @Override
    public int getItemCount() {
        if (dfHomeBannerBeanArrayList != null) {
            return dfHomeBannerBeanArrayList.size();
        }else{
            return 0;
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView itemImg;
        TextView itemTxt;
        public ViewHolder(View itemView) {
            super(itemView);
            itemImg = (ImageView) itemView.findViewById(R.id.item_banner_img);
            itemTxt = (TextView) itemView.findViewById(R.id.item_banner_txt);
        }
    }
}
